package homeWork0825;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class BookMenu {

    private static Scanner sc = new Scanner(System.in);
    private static List<Map<String,Object>> list = new ArrayList<>();
    public static void main(String[] args) {
        System.out.println("---------------------------------------------");
        while(true){
            System.out.println("选择功能");
            System.out.println("1:查询书籍");
            System.out.println("2:修改图书");
            System.out.println("3:添加图书");
            System.out.println("4:删除图书");
            System.out.println("5:退出系统");
            String sr = sc.next();
            switch (sr){
                case "1":
                    String sql = "select * from tbl_book_info where b_status = 1";
                    list = BookInFoDao.excuteQuery(sql);
                    System.out.println(list);
                    break;
                case "2":
                    System.out.println("输入图书编号修改");
                    String b_no = sc.next();
                    System.out.println("输入修改选项 : b_name , b_price");
                    String choose = sc.next();
                    System.out.println("修改内容");
                    String content = sc.next();
                    String sql1 = "update tbl_book_info set "+choose+" = "+content+" where b_no = "+b_no;
                    boolean res = BookInFoDao.excuteUpdate(sql1);
                    if(res){
                        System.out.println("修改成功");
                    }
                    break;
                case "3":
                    System.out.println("输入图书编号");
                    String b_no1 = sc.next();
                    System.out.println("输入图书名称");
                    String b_name = sc.next();
                    System.out.println("输入图书价格");
                    BigDecimal b_price = sc.nextBigDecimal();
                    String sql2 = "insert into tbl_book_info(b_no,b_name,b_price,b_status) values('"+b_no1+"','"+b_name+"',"+b_price+",'1')";
                    if(BookInFoDao.excuteUpdate(sql2)){
                        System.out.println("添加成功");
                    }
                    break;
                case "4":
                    System.out.println("输入删除图书编号");
                    String b_no2 = sc.next();
                    String sql3 = "update tbl_book_info set b_status = 0 where b_no = "+b_no2;
                    if(BookInFoDao.excuteUpdate(sql3)){
                        System.out.println("删除成功");
                    }
                    break;
                case "5":
                    BookInFoDao.close();
                    System.exit(0);
            }
        }
    }
}
